package river_city_ransom.tests;

import java.util.ArrayList;
import java.util.List;

import river_city_ransom.contracts.Dimensions_C;
import river_city_ransom.contracts.GestionCombat_C;
import river_city_ransom.contracts.PersonnageJouable_C;
import river_city_ransom.contracts.Terrain_C;
import river_city_ransom.implementations.Bloc_I;
import river_city_ransom.implementations.Dimensions_I;
import river_city_ransom.implementations.GestionCombat_I;
import river_city_ransom.implementations.Objet_I;
import river_city_ransom.implementations.PersonnageJouable_I;
import river_city_ransom.implementations.Position_I;
import river_city_ransom.implementations.Terrain_I;
import river_city_ransom.services.Bloc;
import river_city_ransom.services.Dimensions;
import river_city_ransom.services.GestionCombat;
import river_city_ransom.services.Objet;
import river_city_ransom.services.PersonnageJouable;
import river_city_ransom.services.Terrain;
import river_city_ransom.types.BlocType;
import river_city_ransom.types.Commande;
import river_city_ransom.types.ObjetNom;
import exceptions.ComposantError;
import junit.framework.TestCase;

public class GestionCombat_T extends TestCase{
	public void test_init_ok() {
		try {
			Dimensions d = new Dimensions_C(new Dimensions_I(50, 50, 30));
			List<Bloc> lb = new ArrayList<>();
			List<Objet> lo = new ArrayList<>();
			lo.add(new  Objet_I(ObjetNom.CHAINE_DE_VELO));
			for(int i = 0; i < 50; i++){
				for(int j = 0; j < 50; j++){
					lb.add(new Bloc_I(BlocType.VIDE, new Position_I(i, j, 0)));
				}
			}
			Terrain t = new Terrain_C(new Terrain_I(d, lb, lo));
			t.init(d, lb, lo);
			GestionCombat gc = new GestionCombat_C(new GestionCombat_I(t));
			gc.init(t);
		}
		catch(ComposantError e) {
			System.err.println("GestionCombat::test_init_pre_ok\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_init_ko() {
		try {
			Dimensions d = new Dimensions_C(new Dimensions_I(50, 50, 30));
			List<Bloc> lb = new ArrayList<>();
			List<Objet> lo = new ArrayList<>();
			lo.add(new  Objet_I(ObjetNom.CHAINE_DE_VELO));
			for(int i = 0; i < 50; i++){
				for(int j = 0; j < 50; j++){
					lb.add(new Bloc_I(BlocType.VIDE, new Position_I(i, j, 0)));
				}
			}
			Terrain t = new Terrain_C(new Terrain_I(d, lb, lo));
			t.init(d, lb, lo);
			GestionCombat gc = new GestionCombat_C(new GestionCombat_I(t));
			t = null;
			gc.init(t);

			System.err.println("GestionCombat::test_init_pre_ko\n\t");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {
		}
	}


	public void test_gerer_pre_ok() {
		try {
			Dimensions d = new Dimensions_C(new Dimensions_I(50, 50, 30));
			List<Bloc> lb = new ArrayList<>();
			List<Objet> lo = new ArrayList<>();
			lo.add(new  Objet_I(ObjetNom.CHAINE_DE_VELO));
			for(int i = 0; i < 50; i++){
				for(int j = 0; j < 50; j++){
					lb.add(new Bloc_I(BlocType.VIDE, new Position_I(i, j, 0)));
				}
			}
			Terrain t = new Terrain_C(new Terrain_I(d, lb, lo));
			t.init(d, lb, lo);
			GestionCombat gc = new GestionCombat_C(new GestionCombat_I(t));
			gc.init(t);
			gc.avantPasJeu();
			gc.gerer(null, null);
		}
		catch(ComposantError e) {
			System.err.println("GestionCombat::test_init_pre_ok\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_gerer_pre_ko() {
		try {
			Dimensions d = new Dimensions_C(new Dimensions_I(50, 50, 30));
			List<Bloc> lb = new ArrayList<>();
			List<Objet> lo = new ArrayList<>();
			lo.add(new  Objet_I(ObjetNom.CHAINE_DE_VELO));
			for(int i = 0; i < 50; i++){
				for(int j = 0; j < 50; j++){
					lb.add(new Bloc_I(BlocType.VIDE, new Position_I(i, j, 0)));
				}
			}
			Terrain t = new Terrain_C(new Terrain_I(d, lb, lo));
			t.init(d, lb, lo);
			GestionCombat gc = new GestionCombat_C(new GestionCombat_I(t));
			gc.init(t);
			gc.gerer(null, null);
			System.err.println("GestionCombat::test_init_pre_ko\n\t");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_gerer_pre_ko2() {
		try {
			Dimensions d = new Dimensions_C(new Dimensions_I(50, 50, 30));
			List<Bloc> lb = new ArrayList<>();
			List<Objet> lo = new ArrayList<>();
			lo.add(new  Objet_I(ObjetNom.CHAINE_DE_VELO));
			for(int i = 0; i < 50; i++){
				for(int j = 0; j < 50; j++){
					lb.add(new Bloc_I(BlocType.VIDE, new Position_I(i, j, 0)));
				}
			}
			Terrain t = new Terrain_C(new Terrain_I(d, lb, lo));
			t.init(d, lb, lo);
			GestionCombat gc = new GestionCombat_C(new GestionCombat_I(t));
			gc.init(t);
			gc.gerer(Commande.BAS, null);
			System.err.println("GestionCombat::test_init_pre_ko\n\t");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_gerer_pre_ko3() {
		try {
			Dimensions d = new Dimensions_C(new Dimensions_I(50, 50, 30));
			List<Bloc> lb = new ArrayList<>();
			List<Objet> lo = new ArrayList<>();
			lo.add(new  Objet_I(ObjetNom.CHAINE_DE_VELO));
			for(int i = 0; i < 50; i++){
				for(int j = 0; j < 50; j++){
					lb.add(new Bloc_I(BlocType.VIDE, new Position_I(i, j, 0)));
				}
			}
			Terrain t = new Terrain_C(new Terrain_I(d, lb, lo));
			t.init(d, lb, lo);
			GestionCombat gc = new GestionCombat_C(new GestionCombat_I(t));
			gc.init(t);
			gc.gerer(Commande.BAS, Commande.BAS);
			System.err.println("GestionCombat::test_init_pre_ko\n\t");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_gerer_pre_ko4() {
		try {
			Dimensions d = new Dimensions_C(new Dimensions_I(50, 50, 30));
			List<Bloc> lb = new ArrayList<>();
			List<Objet> lo = new ArrayList<>();
			lo.add(new  Objet_I(ObjetNom.CHAINE_DE_VELO));
			for(int i = 0; i < 50; i++){
				for(int j = 0; j < 50; j++){
					lb.add(new Bloc_I(BlocType.VIDE, new Position_I(i, j, 0)));
				}
			}
			Terrain t = new Terrain_C(new Terrain_I(d, lb, lo));
			t.init(d, lb, lo);
			GestionCombat gc = new GestionCombat_C(new GestionCombat_I(t));
			gc.init(t);
			gc.gerer(Commande.HAUT, null);
			System.err.println("GestionCombat::test_init_pre_ko\n\t");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_gerer_pre_ko5() {
		try {
			Dimensions d = new Dimensions_C(new Dimensions_I(50, 50, 30));
			List<Bloc> lb = new ArrayList<>();
			List<Objet> lo = new ArrayList<>();
			lo.add(new  Objet_I(ObjetNom.CHAINE_DE_VELO));
			for(int i = 0; i < 50; i++){
				for(int j = 0; j < 50; j++){
					lb.add(new Bloc_I(BlocType.VIDE, new Position_I(i, j, 0)));
				}
			}
			Terrain t = new Terrain_C(new Terrain_I(d, lb, lo));
			t.init(d, lb, lo);
			GestionCombat gc = new GestionCombat_C(new GestionCombat_I(t));
			gc.init(t);
			gc.gerer(Commande.BAS, Commande.HAUT);
			System.err.println("GestionCombat::test_init_pre_ko\n\t");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_gerer_pre_ko6() {
		try {
			Dimensions d = new Dimensions_C(new Dimensions_I(50, 50, 30));
			List<Bloc> lb = new ArrayList<>();
			List<Objet> lo = new ArrayList<>();
			lo.add(new  Objet_I(ObjetNom.CHAINE_DE_VELO));
			for(int i = 0; i < 50; i++){
				for(int j = 0; j < 50; j++){
					lb.add(new Bloc_I(BlocType.VIDE, new Position_I(i, j, 0)));
				}
			}
			Terrain t = new Terrain_C(new Terrain_I(d, lb, lo));
			t.init(d, lb, lo);
			GestionCombat gc = new GestionCombat_C(new GestionCombat_I(t));
			gc.init(t);
			gc.gerer(Commande.BAS, Commande.DROITE);
			System.err.println("GestionCombat::test_init_pre_ko\n\t");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {
		}
	}


	public void test_gererCommande_pre_ok() {
		try {
			Dimensions d = new Dimensions_C(new Dimensions_I(50, 50, 30));
			List<Bloc> lb = new ArrayList<>();
			List<Objet> lo = new ArrayList<>();
			lo.add(new  Objet_I(ObjetNom.CHAINE_DE_VELO));
			for(int i = 0; i < 50; i++){
				for(int j = 0; j < 50; j++){
					lb.add(new Bloc_I(BlocType.VIDE, new Position_I(i, j, 0)));
				}
			}
			Terrain t = new Terrain_C(new Terrain_I(d, lb, lo));
			t.init(d, lb, lo);
			GestionCombat gc = new GestionCombat_C(new GestionCombat_I(t));
			gc.init(t);
			gc.avantPasJeu();

			String n = "Alex";
			Dimensions k = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, k, f, pv);

			gc.gerer(null, null);

			gc.gererCommande(p, Commande.BAS);

		}
		catch(ComposantError e) {
			System.err.println("GestionCombat::test_gererCommande_pre_ok\n\t" + e.getMessage());
			fail("Exception non levée.");
		}
	}

	public void test_gererCommande_pre_ko() {
		try {
			Dimensions d = new Dimensions_C(new Dimensions_I(50, 50, 30));
			List<Bloc> lb = new ArrayList<>();
			List<Objet> lo = new ArrayList<>();
			lo.add(new  Objet_I(ObjetNom.CHAINE_DE_VELO));
			for(int i = 0; i < 50; i++){
				for(int j = 0; j < 50; j++){
					lb.add(new Bloc_I(BlocType.VIDE, new Position_I(i, j, 0)));
				}
			}
			Terrain t = new Terrain_C(new Terrain_I(d, lb, lo));
			t.init(d, lb, lo);
			GestionCombat gc = new GestionCombat_C(new GestionCombat_I(t));
			gc.init(t);
			gc.avantPasJeu();
			gc.gererCommande(null, null);
			System.err.println("GestionCombat::test_gererCommande_pre_ko\n\t");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {

		}
	}

	public void test_gererCommande_pre_ko2() {
		try {
			Dimensions d = new Dimensions_C(new Dimensions_I(50, 50, 30));
			List<Bloc> lb = new ArrayList<>();
			List<Objet> lo = new ArrayList<>();
			lo.add(new  Objet_I(ObjetNom.CHAINE_DE_VELO));
			for(int i = 0; i < 50; i++){
				for(int j = 0; j < 50; j++){
					lb.add(new Bloc_I(BlocType.VIDE, new Position_I(i, j, 0)));
				}
			}
			Terrain t = new Terrain_C(new Terrain_I(d, lb, lo));
			t.init(d, lb, lo);
			GestionCombat gc = new GestionCombat_C(new GestionCombat_I(t));
			gc.init(t);
			gc.gererCommande(null, null);
			System.err.println("GestionCombat::test_gererCommande_pre_ko2\n\t");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {

		}
	}

	public void test_avantPasJeu_pre_ok(){
		try {
			Dimensions d = new Dimensions_C(new Dimensions_I(50, 50, 30));
			List<Bloc> lb = new ArrayList<>();
			List<Objet> lo = new ArrayList<>();
			lo.add(new  Objet_I(ObjetNom.CHAINE_DE_VELO));
			for(int i = 0; i < 50; i++){
				for(int j = 0; j < 50; j++){
					lb.add(new Bloc_I(BlocType.VIDE, new Position_I(i, j, 0)));
				}
			}
			Terrain t = new Terrain_C(new Terrain_I(d, lb, lo));
			t.init(d, lb, lo);
			GestionCombat gc = new GestionCombat_C(new GestionCombat_I(t));
			gc.init(t);
			gc.avantPasJeu();
		}catch(ComposantError e) {
			System.err.println("GestionCombat::test_avantPasJeu_pre_ok\n\t" + e.getMessage());
			fail("Exception non levée.");
		}
	}
	
	public void test_avantPasJeu_pre_ko(){
		try {
			Dimensions d = new Dimensions_C(new Dimensions_I(50, 50, 30));
			List<Bloc> lb = new ArrayList<>();
			List<Objet> lo = new ArrayList<>();
			lo.add(new  Objet_I(ObjetNom.CHAINE_DE_VELO));
			for(int i = 0; i < 50; i++){
				for(int j = 0; j < 50; j++){
					lb.add(new Bloc_I(BlocType.VIDE, new Position_I(i, j, 0)));
				}
			}
			Terrain t = new Terrain_C(new Terrain_I(d, lb, lo));
			t.init(d, lb, lo);
			GestionCombat gc = new GestionCombat_C(new GestionCombat_I(t));
			gc.init(t);
			gc.avantPasJeu();
			gc.avantPasJeu();
			
			System.err.println("GestionCombat::test_avantPasJeu_pre_ok\n\t");
			fail("Exception non levée.");
		}catch(ComposantError e) {
		}
	}

}
